package com.qi.invokeclient.controller;

import com.qi.invokeclient.vo.Order;
import io.dapr.client.DaprClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class PublishController {

    @Autowired
    private DaprClient client;

    @GetMapping("publish")
    public void publish() {

        for (int i = 0; i <= 10; i++) {
            Order order = new Order();
            order.setOrderId(i);

            client.publishEvent("pubsub", "topic", order).block();
            log.info("Published data: {}", order.getOrderId());
        }
    }
}

